<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子2-JS进阶（二）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子1

                    var fn = null;
                    function foo() {
                        var a = 2;
                        function innnerFoo() {
                            console.log(a);
                        }
                        fn = innnerFoo; // 将 innnerFoo的引用，赋值给全局变量中的fn
                    }

                    function bar() {
                        fn(); // 此处保留innerFoo的引用
                    }

                    foo();
                    bar(); // 2
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/2.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>